package com.sailing.service.impl;

import com.alibaba.fastjson.JSON;
import com.sailing.bo.WiselyResponse;
import com.sailing.service.PushService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.simp.SimpMessagingTemplate;
import org.springframework.stereotype.Service;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 推送业务处理
 *
 * @author : nanji
 * @create 2017-12-13 11:09
 */
@Service
public class PushServiceImpl  implements PushService {

    public static final Logger LOGGER = LoggerFactory.getLogger(PushServiceImpl.class);
    @Autowired
    private SimpMessagingTemplate simpMessagingTemplate;

    /**
     * 发送消息
     * @param wiselyResponse
     * @return
     */
    @Override
    public String sendMessage(WiselyResponse wiselyResponse) {
        simpMessagingTemplate.convertAndSend(wiselyResponse.getTopic(),wiselyResponse.getResponseMessage());
        LOGGER.info("{}:{}",new Date(),wiselyResponse.getResponseMessage());
        return "success";
    }

    @Override
    public String receiveMesager(WiselyResponse wiselyResponse) throws Exception {
       String jsonStr= JSON.toJSONString(wiselyResponse);
        LOGGER.info("接收内容="+wiselyResponse.getResponseMessage());
        return "success";
    }
}
